# encoding: UTF-8

class Admin::PhotosController < ApplicationController

  before_filter :user_signed_in?
  
  def index
    @photos = Photo.all
    set_seo_meta '图片管理'
  end

  def new
    @category = Node.open_status.photo_category
		@photo = Photo.new
    set_seo_meta '图片新增'
  end

  def create
    @photo = Photo.new(params[:photo])
    if @photo.save!
      redirect_to photos_path, notice: '新增成功!'
    else
      redirect_referrer_or_default default
    end  
  end

  def edit
    @category = Node.open_status.photo_category
    @photo = Photo.find(params[:id]) 
    set_seo_meta '图片修改'
  end

  def update
    @photo = Photo.find(params[:id])
    if @photo.update_attributes!(params[:session])
      redirect_to photos_path, notice:'修改成功'
    else
      redirect_referrer_or_defautl default
    end
  end

  def destroy
    if Photo.delete(params[:id])
      redirect_to photos_path, notice:'删除成功'
    else
      redirect_referrer_or_default default
    end  
  end

  def category
    @photos = Photo.where("category='#{params[:id]}'").paginate(:page => params[:page], :per_page => '2')
    set_seo_meta '分类浏览'
  end

end
